#include "solvercachegrouping.h"

SolverCacheGrouping::SolverCacheGrouping(const map<string, vector<cache> >& workingDataSet) : Solver(workingDataSet)
{
}

void SolverCacheGrouping::groupByCache(void)
{
    for (std::map<string, vector<cache> >::const_iterator mapIt = dataSet.begin(); mapIt
            != dataSet.end(); ++mapIt)
    {
        for (std::vector<cache>::const_iterator dataIt = mapIt->second.begin(); dataIt
                != mapIt->second.end(); ++dataIt)
        {
            std::map<cache, vector<string> >::iterator findIt =
                groupedCachesToName.find(*dataIt);
            if (findIt == groupedCachesToName.end())
            {
                // Not there
                vector<string> nameList;
                nameList.push_back(mapIt->first);
                groupedCachesToName.insert(std::make_pair(*dataIt, nameList));
            }
            else
            {
                // Already there
                findIt->second.push_back(mapIt->first);
            }
        }
    }
}

map<cache, vector<string> >& SolverCacheGrouping::getCacheGrouping()
{
    return groupedCachesToName;
}
